package com.example.demo.createanddestroyobjects.one.one3;

import java.io.Serializable;
import java.util.Objects;

public class Singleton {
    public static class test1{
        private static final  test1 In = new test1();
        private test1(){}
        public static void setIn(){

        }
    }
    //序列化保证实例是快速的
    public static class test12 implements Serializable {
        //创建私有的实例化对象 确保全局唯一性
        private static final  test12 In = new test12();
        //私有的保证了每次只实例化一次
        private test12(){}
        //静态工厂方法保证安全性
        public static test12 getInstance(){ return In;}
        //客户端调用这个
        public static void setIn(){ }
        //保证不需要每次反序列化
        private Object readResolve(){return  In;}
    }
}
